package com.cup.jpa.demo.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.cup.jpa.demo.model.User;
import com.cup.jpa.demo.server.UserService;

@RestController
@RequestMapping("view")
public class ThymeleafController {
	
	@Autowired
	private UserService userService;
	
	@GetMapping(value = "/user")
    public ModelAndView getAll() {
		
		ModelAndView mv = new ModelAndView();
		
		mv.setViewName("/demo/userlist");
		mv.addObject("userlist", userService.getUserlist());
		
		return mv;
    }
	
	@GetMapping(value = "/get")
    public User get(@RequestParam String id) {
        return userService.getUserById(Integer.valueOf(id));
    }
}
